package main

import (
	"errors"
	"fmt"
	"net"
	"net/http"
	"net/rpc"
)

type HelloWorld struct {
}

type SayHelloRequest struct {
	Name string
}

type SayHelloResponse struct {
	Data string
}

func (t *HelloWorld) SayHello(req SayHelloRequest, resp *SayHelloResponse) (err error) {
	if resp == nil {
		return errors.New("参数错误")
	}
	if req.Name == "" {
		return errors.New("参数错误")
	}
	resp.Data = "Hello " + req.Name
	return nil
}

func main() {
	rpc.Register(new(HelloWorld))
	rpc.HandleHTTP()

	listenser, err := net.Listen("tcp", "127.0.0.1:6789")
	if err != nil {
		panic(err)
	}

	fmt.Println("Start listen Port :6789")

	http.Serve(listenser, nil)
	return
}
